%% This program is calculate the penetration depth for water
% the input parameter is incidence angle (qz) and energy (keV) 
% attenuatin length in Angstrom
function out=PD(qz,energy,Attl)
lambda=12.398/energy; % Anstroms.  Energy in unit of keV

alpha=asin(qz*lambda/4/pi);

k0=2*pi/lambda;
r0=2.82e-5;  % Anstroms
rho_ele_water=0.334;%1/cubicAnstroms
delta=2*pi*rho_ele_water*r0/(k0)^2;

alpha_c=sqrt(2*delta);
beta=1/2/k0/Attl; % mu is attenuation length normal to surface In the unit of angstrom

out=(1/sqrt(2)/k0)*(((sin(alpha).^2-sin(alpha_c)^2).^2+4*beta^2).^(1/2)+sin(alpha_c)^2-sin(alpha).^2).^(-1/2);

